home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-24 | 3.4 KB | 175 lines | [TEXT/MMCC] |
- // ===========================================================================
- // CNetDemoApp.cp ©1995 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- //
- // Example program showing how to use UModalDialogs
-
- #include "SenderSetup.h"
-
- #include "OutPoint.h"
-
- #include <URegistrar.h>
- #include <UReanimator.h>
-
- #include <LEditField.h>
- #include <LTabGroup.h>
- #include <LCaption.h>
- #include <LRadioGroup.h>
- #include <LStdControl.h>
- #include <LDialogBox.h>
- #include <UModalDialogs.h>
- #include <PP_Messages.h>
-
- #include "Fractal.h"
-
- #pragma cplusplus on
-
-
-
- #include <string.h>
-
- const ResIDT WIND_NewSession = 128;
- const PaneIDT pTCPButton = 1;
- const PaneIDT pAtalkButton = 2;
- const PaneIDT pAddress = 11;
-
-
- OutPoint* gOutPoint = nil;
-
-
-
- void InitSender()
-
- {
- InitOpenTransport();
-
- /*
- URegistrar::RegisterClass(LWindow::class_ID, LWindow::CreateWindowStream);
- URegistrar::RegisterClass(LEditField::class_ID, LEditField::CreateEditFieldStream);
- URegistrar::RegisterClass(LTabGroup::class_ID, LTabGroup::CreateTabGroupStream);
- URegistrar::RegisterClass(LCaption::class_ID, LCaption::CreateCaptionStream);
- URegistrar::RegisterClass(LStdButton::class_ID, LStdButton::CreateStdButtonStream);
- URegistrar::RegisterClass(LStdRadioButton::class_ID, LStdRadioButton::CreateStdRadioButtonStream);
- URegistrar::RegisterClass(LRadioGroup::class_ID, LRadioGroup::CreateRadioGroupStream);
- URegistrar::RegisterClass(LDialogBox::class_ID, LDialogBox::CreateDialogBoxStream);
- */
- }
-
- void CleanUpSender()
-
- {
- if (gOutPoint)
- delete gOutPoint;
- }
-
-
-
- void SpawnSender()
-
- {
-
- if (gOutPoint)
- return;
-
- DialogRef dia = GetNewDialog(999, nil, WindowRef (-1));
- short xitem;
-
- do {
- ModalDialog(nil, &xitem);
- } while (xitem != 1);
-
- short itemType;
- Handle itemH;
- Rect box;
-
- GetDialogItem(dia, 2, &itemType, &itemH, &box);
-
-
-
- /*
- StDialogHandler dlog(WIND_NewSession, nil);
- MessageT msg = 0;
-
- while (!msg)
- msg = dlog.DoDialog();
-
- if (msg == msg_Cancel)
- return;
- */
-
- Str255 address;
- char configstr[80];
-
- GetDialogItemText(itemH, address);
- DisposeDialog(dia);
-
- /*
- LEditField* adrStr = (LEditField*) dlog.GetDialog()->FindPaneByID(pAddress);
- LStdRadioButton* tcpBut = (LStdRadioButton*) dlog.GetDialog()->FindPaneByID(pTCPButton);
- */
- if (1)
- // if (tcpBut->GetValue())
- strcpy(configstr, "udp");
- else
- strcpy(configstr, "ddp");
-
- // adrStr->GetDescriptor(address);
- p2cstr(address);
-
-
- // for now we just create a sender
-
- volatile OutPoint* point = nil;
-
- try {
- point = new OutPoint(configstr, (char*) address, OUR_PORT);
- }
- catch(...) {
- delete point;
- }
- gOutPoint = point;
-
- }
-
-
- void
- BlastData()
- {
- if (gOutPoint == nil)
- return;
-
- DataDesc theData;
-
- PixMapHandle pmap = GetGWorldPixMap(gOffscreenGWorld);
- char *baseAddr = GetPixBaseAddr(pmap);
- long rowBytes = (*pmap)->rowBytes&0x3fff;
-
- #define VV 100
- #define HH 165
- #define RB 256
- #define NR 4
-
- int v;
- OTData data[NR+1];
-
- data[0].fData = (UInt8*)&theData;
- data[0].fLen = 20;
- data[0].fNext = &data[1];
- for (v=VV; v<(VV+175); v+=NR) {
- theData.rowBytes=RB;
- theData.rowSize=RB;
- theData.numRows=NR;
- theData.xPos=0;
- theData.yPos=v-VV;
- int ix;
- for (ix=0; ix<NR; ix++) {
- data[ix+1].fData = baseAddr+HH+rowBytes*(v+ix);
- data[ix+1].fLen = RB;
- data[ix+1].fNext = &data[ix+2];
- // BlockMoveData(baseAddr+HH+rowBytes*(v+ix), &theData.data[ix*RB], RB);
- }
- data[NR].fNext = nil;
- gOutPoint->SendData(&data, kNetbufDataIsOTData);
- }
- }
-